/**
 * @description 下载文件公共方法
 * @param type 文件类型
 * @param res 二进制流
 */
import { message } from 'ant-design-vue'
export function downloadFile(fileName, type, res) {
  // console.log(res, '[[[[[[[[[[[[[[[[[[[[')
  const typeData = {
    xls: 'application/vnd.ms-excel',
    xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
    doc: 'application/msword',
    docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
    pdf: 'pplication/pdf'
  }
  if (!res) {
    return
  }

  const url = window.URL.createObjectURL(
    new Blob([res], {
      type: typeData[type]
    })
  )
  const link = document.createElement('a')
  link.style.display = 'none'
  link.href = url
  link.setAttribute('download', fileName + '.' + type || 'file.' + type)
  document.body.appendChild(link)
  link.click()
  message.success('下载文件成功！')
}
